package com.cwd.arm.domain.repository.impl;

import com.cwd.arm.infrastructure.dao.TargetConfirmAmountDao;
import com.cwd.arm.infrastructure.po.TargetConfirmAmountPo;
import com.cwd.arm.domain.entity.TargetConfirmAmountEntity;
import com.cwd.arm.domain.repository.TargetConfirmAmountRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
* Description:目标确认金额
* Created on 2022年01月15日
* @author  yan
*/
@Repository
public class TargetConfirmAmountRepositoryImpl implements TargetConfirmAmountRepository{

    @Autowired
    private TargetConfirmAmountDao dao;

    @Override
    public void save(TargetConfirmAmountEntity entity) {
        dao.save(convertToPo(entity));
    }

    @Transactional
    @Override
    public void saveOrUpdate(TargetConfirmAmountEntity entity) {
        dao.delByProjectId(entity.getProjectId(),entity.getYear());
        save(entity);
    }

    private TargetConfirmAmountPo convertToPo(TargetConfirmAmountEntity entity){
        TargetConfirmAmountPo TargetConfirmAmountPo = new TargetConfirmAmountPo();
        BeanUtils.copyProperties(entity,TargetConfirmAmountPo);
        return TargetConfirmAmountPo;
    }

}
